//
//  WJYSearchTableViewCell.m
//  WWLNetease
//
//  Created by dllo on 16/1/4.
//  Copyright © 2016年 Echo.Jobs. All rights reserved.
//

#import "WJYSearchTableViewCell.h"

@interface WJYSearchTableViewCell ()

@property (nonatomic, retain) UILabel *label;

@end

@implementation WJYSearchTableViewCell

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    int x = 15 * KPropotionWidth;
    int y = 20 * SIZE;
    
    for (int i = 0; i < self.arr.count; i++) {
        
        self.label = [[UILabel alloc] init];
        
        float r = arc4random() % 255;
        float b = arc4random() % 255;
        float g = arc4random() % 255;
        
        self.label.textColor = [UIColor colorWithRed:r / 255.f green:g / 255.f blue:b / 255.f alpha:1.0];
        
        WJYNewsModel *newsSearchM = [self.arr objectAtIndex:i];
        self.label.text = newsSearchM.hotWord;
        
        CGRect w = [newsSearchM.hotWord boundingRectWithSize:CGSizeMake(SCREEN_FRAME.size.width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17 * KPropotionWidth]} context:nil];
        
        self.label.frame = CGRectMake(x, y, w.size.width, 30 * SIZE);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [tap addTarget:self action:@selector(tap:)];
        tap.numberOfTapsRequired = 1;
        tap.numberOfTouchesRequired = 1;
        [_label addGestureRecognizer:tap];
        _label.userInteractionEnabled = YES;
        _label.tag = 10000 + i;
        x += w.size.width + 20 * KPropotionWidth;
        if (x > SCREEN_FRAME.size.width - SCREEN_FRAME.size.width / 2.2) {
            x = 15 * KPropotionWidth;
            y += 35 * SIZE;
        }
        [self.contentView addSubview:_label];
        
    }
    
}

-(void)tap:(UITapGestureRecognizer *)tap {
    
    UILabel *label = (UILabel *)[self.contentView viewWithTag:tap.view.tag];
    
    [self.delegate passValue:label.text];
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
